import type { ChanWuRow, EditFormData, JianCeRow, MainTableRow, ZhiLiRow, ZhiliJianCeRow } from './create'

export function useInitForm() {
  const getData = () => {
    return {
      Name: '',
      ContactName: '',
      Remark: '',
      ContactTel: '',
      CreditCode: '',
      Longitude: undefined,
      Latitude: undefined,
      NEIndustryCode: '',
      OwnerOrgCode: '',
      NEIndustry: {},
      Address: '',
      LegalPerson: '',
      InstallDate: '',
      EnvOrgCode: '',
      Altitude: 0,
      DistrictID: '',
      ObjID: '',
    }
  }

  const formData = ref<EditFormData>(getData())
  const initForm = () => {
    formData.value = getData()
  }

  return { formData, initForm }
}

export function useEntPageData() {
  const route = useRoute()
  const id = computed(() => {
    const { id } = route.params
    return id as string
  })
  const isReadOnly = computed(() => {
    return route.name === 'document-manager-detail'
  })
  const isCreate = computed(() => {
    return !id.value
  })

  return { id, isCreate, isReadOnly }
}

export function useInitMainTableForm(): { formData: Ref<MainTableRow>, initForm: () => void } {
  const getData = (): MainTableRow => {
    return {
      Name: '',
      PointCode: '',
      MN: '',
      Location: '',
      ObjID: '',
      AssetCode: '',
    }
  }
  const formData = ref<MainTableRow>(getData())
  const initForm = () => {
    formData.value = getData()
  }

  return { formData, initForm }
}

export function useInitChanWuForm(): { formData: Ref<ChanWuRow>, initForm: () => void } {
  const getData = (): ChanWuRow => {
    return {
      Name: '',
      LimitLower: 0,
      Location: '',
      ObjID: '',
    }
  }
  const formData = ref<ChanWuRow>(getData())
  const initForm = () => {
    formData.value = getData()
  }

  return { formData, initForm }
}
export function useInitZhiLiForm(): { formData: Ref<ZhiLiRow>, initForm: () => void } {
  const getData = (): ZhiLiRow => {
    return {
      Name: '',
      ProduceIDs: [],
      Location: '',
      ObjID: '',
    }
  }
  const formData = ref<ZhiLiRow>(getData())
  const initForm = () => {
    formData.value = getData()
  }

  return { formData, initForm }
}

export function useInitJianCeForm(): { formData: Ref<JianCeRow>, initForm: () => void } {
  const getData = (): JianCeRow => {
    return {
      Name: '',
      MN: '',
      PointCode: '',
      Location: '',
      ObjID: '',
      ParentId: '',
      AssetCode: '',
      EnablePowerLowerLimit: false,
      PowerLimit: 0,
    }
  }
  const formData = ref<JianCeRow>(getData())
  const initForm = () => {
    formData.value = getData()
  }

  return { formData, initForm }
}

export function useInitZhiliJianCeForm(): { formData: Ref<ZhiliJianCeRow>, initForm: () => void } {
  const getData = (): ZhiliJianCeRow => {
    return {
      Name: '',
      MN: '',
      PointCode: '',
      Location: '',
      PowerLimit: 0,
      PowerDuration: 0,
      ObjID: '',
      ParentId: '',
      AssetCode: '',
      EnablePowerLowerLimit: false,
    }
  }
  const formData = ref<ZhiliJianCeRow>(getData())
  const initForm = () => {
    formData.value = getData()
  }

  return { formData, initForm }
}
